<script>
var team_exist_flag = false;
window.addEvent('domready', function() {
   
   	for(i=0;i<24;i++)
	{
	var obj ='ftask'+(i+1).toString();
		$(obj).setStyles({width:'80px',height:'55px','background-color': '#E0ECFF',margin: '2px 1px 2px 2px'});		
	}
	$j('#task_exec_list').panel();
});

//显示选择任务的申请执行队伍情况，一般是6个队伍就关闭申请了
function showtaskexec(taskid){

	var callback = function(data){
	if(data[0]['status']=='ok')
	{
	//拿到了数据，显示
	var datar = data[0]['data'];
	var length = data[0]['data'].length;
	$('teamcount').value=length;	
		//alert(length);
			for(i=0;i<length;i++)
			{
			var htmstr = "<tr id="+'ddrow'+i+">";
			var td = '<td>'+datar[i]['id_team']+'</td>'+'<td>'+datar[i]['member_num']+'</td>'+'<td>'+datar[i]['team_score']+'</td>'+'<td>'+datar[i]['team_capcity']+'</td>'+'<td>'+datar[i]['taskPageNum']+'</td>'+'<td>'+datar[i]['bTime']+'</td>'+'<td>'+datar[i]['city']+'</td>'+'<td>'+datar[i]['zip_code']+'</td>';
			htmstr = htmstr+td+'</tr>';
			//alert(htmstr);
			var tmp ='ddrow'+i.toString();
				if($(tmp)!=null)
				{
				}
				else
				{
				$j('#execlist').append(htmstr);
				}
			if(datar[i]['id_team']==Cookie.read('teamId__'))	
			{team_exist_flag = true;}
			}		
	}
	else
	{
	$j.messager.alert('任务执行数据获取失败','请刷新尝试或者通知管理员');
	}
	};
	var datastr = 'id_gezi_task='+taskid;
	var urlstr = '__APP__/Util/getTaskexecList';
	ajaxGet(urlstr,datastr,callback);
}


//申请承接任务
function applyTask(taskid,teamcount){

	if(taskid!='任务ID')
	{
	var teamid= $('team_id').value;
	var nowcap= parseInt($('now_capcity').value);
	var score= parseInt($('score').value);	
	var tPageNum= parseInt($('fTpageNum').innerHTML);
		
		if($chk(teamid))//是团队成员
		{
			if(teamcount<6)
			{
				msg("<span style='color:red;'>注意</span>",'请认真查看任务详情后再申请承接');
				if(nowcap>=tPageNum)
				{
				addApplytask(taskid,teamid,tPageNum,score);
				}
				else
				{
				$j.messager.alert('错误','团队投放能力为'+nowcap+'小于任务张数'+tPageNum+"<br/>推荐创建<span style='color:red;'>团队交换任务</span>");		
				}
			}
			else
			{
			$j.messager.alert("<span style='color:red;'>任务申请满员</span>",'每个任务仅仅允许6个团队申请');
			}		
		}	
		else
		{
		$j.messager.alert('错误','你还不是团队成员，请先加入或者创建团队');
		}
	}
}
//ajax提交后台1.insert taskexec表一条记录，update team表的now_capcity,提交一条申请
function addApplytask(taskid,teamid,taskpage,score)
{ 
	var callback = function(data){	
		if(data[0]['status']=='ok')
		{
		$j.messager.alert('提交成功','恭喜你,申请已经提交');
		//window.location.reload();
		}
		else
		{
		$j.messager.alert('出错了','服务器存取错误,请重试或者联系客服');		
		}
	};
	var datastr = 'id_gezi_task='+taskid+'&id_team='+teamid+'&taskpage='+taskpage+'&score='+score;
	var urlstr = '__APP__/Task/addApplytask';
	if(!team_exist_flag)
	{
	ajaxGet(urlstr,datastr,callback);
	}
	else
	{
	$j.messager.alert('已申请过','您的团队已经申请了此任务');		
	}
	
}
</script>

<div style="text-align:center;">
<center>
<table width="650" style="font-size:12px;">
<tr >
	<td align="center" style="width:370px;">
			<label style="font-size:12px">选择任务<select  id="seltaskid2" onChange="if(this.value!='任务ID')showtask('ftask',this.value);showtaskexec(this.value);">
			  <option value="任务ID" selected>任务ID</option>				  
			  <volist name="TaskList1" id="voo">
			  <option value="{$voo.id_gezi_task}">{$voo.id_gezi_task}</option>
			  </volist>
		  		</select>
		  </label>
		  	<volist name="TaskList1" id="vbo">
			  <input type="hidden" value="{$vbo.task_ctime}" id="task_ctime{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.TpageNum}" id="TpageNum{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.percent}" id="percent{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.status}" id="status{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.task_type}" id="task_type{$vbo.id_gezi_task}"	/>			  				  				  				  		  
			  <input type="hidden" value="{$vbo.tTgezi}" id="tTgezi{$vbo.id_gezi_task}"	/>	
			  <input type="hidden" value="{$vbo.nowGezi}" id="nowGezi{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.nowLoc}" id="nowLoc{$vbo.id_gezi_task}"	/>			  					  				  
			  <input type="hidden" value="{$vbo.score}" id="score{$vbo.id_gezi_task}"	/>					  				  
			  <input type="hidden" value="{$vbo.id_gezi_task}" id="id_gezi_task{$vbo.id_gezi_task}"	/>
		  </volist>
		<table style="font-size:12px" 	 border="1">
		<th colspan="11">选中要承接的任务</th>
		<tr bgcolor="#FF9900" ><td colspan="11">任务ID:<span id="fid_gezi_task"></span></td></tr>				
		<tr><td>创建时间</td><td>张数</td><td colspan="3">满格率</td><td>占位</td><td>空位</td><td>格子总数</td><td>类别</td><td>状态</td><td>分数</td></tr>
		<tr><td><span id="ftask_ctime"></span></td><td><span id="fTpageNum"></span></td><td colspan="3"><span id="fpercent"></span></td>
		<td><span id="fnowGezi"></span></td><td><span id="fnowLoc"></span></td>
		<td><span id="ftTgezi"></span></td><td><span id="ftask_type"></span></td><td><span id="fstatus"></span></td>
		<td><span id="fscore"></span></td></tr>			
		</table>
	</td>
	
	<td align="center"> 
	<br/><br/><br/>	
	<div id="task_exec_list" title="团队申请承接记录"   collapsible="false">  
	<table id="execlist" style="font-size:12px" border="1" width="320">
	<tr ><td>团队ID</td><td>人数</td><td>评分</td><td>能力</td><td>任务张数</td><td>承接时间</td><td>城市</td><td>邮编</td></tr>
	</table>
	<input type="button" id="apltask" value="申请承接此任务" onclick="applyTask($('seltaskid2').value,$('teamcount').value);" />
	<input type="hidden" value="{$_SESSION['UserInfo']['team_id']}" id="team_id" />
	<input type="hidden" value="0" id="teamcount" />	
	<input type="hidden" value="{$_SESSION['UserInfo2']['now_capcity']}" id="now_capcity" />
	<input type="hidden" value="{$_SESSION['UserInfo2']['team_score']}" id="score" />
	
	</div>
	</td>
	
</tr>
<tr>
	<td align="center" colspan="2">
	<div  id="taskpdts" style="border:#E0ECFF solid 1px;">
	<table style="font-size:12px">
	<tr  bgcolor="#FF9900"><td colspan="4">正面</td> <td colspan="4">反面</td> </tr>
	<tr><td><div id="ftask1"></div></td><td><div id="ftask2"></div></td><td><div id="ftask3"></div></td><td><div id="ftask4"></div></td>
	<td><div id="ftask13"></div></td><td><div id="ftask14"></div></td><td><div id="ftask15"></div></td><td><div id="ftask16"></div></td></tr>
	
	<tr><td><div id="ftask5"></div></td><td><div id="ftask6"></div></td><td><div id="ftask7"></div></td><td><div id="ftask8"></div></td>
	<td><div id="ftask17"></div></td><td><div id="ftask18"></div></td><td><div id="ftask19"></div></td><td><div id="ftask20"></div></td></tr>
	
	<tr><td><div id="ftask9"></div></td><td><div id="ftask10"></div></td><td><div id="ftask11"></div></td><td><div id="ftask12"></div></td>
	<td><div id="ftask21"></div></td><td><div id="ftask22"></div></td><td><div id="ftask23"></div></td><td><div id="ftask24"></div></td></tr>
			
	</table>
	</div>
	</td>
	
</tr>

</table>
</center>
</div>
